# Maintainer: Ariadne Conill <ariadne@dereferenced.org>
pkgname=libubox
pkgver=20230523
pkgrel=0
pkgdesc="OpenWrt utility and data structures library"
url="https://git.openwrt.org/project/ustream-ssl.git"
arch="all"
license="ISC"
depends=""
depends_dev="libubox json-c-dev"
makedepends="cmake $depends_dev"
subpackages="libblobmsg jshn $pkgname-static $pkgname-dev"
_owrtgit=75a3b870
_owrtver="${pkgver:0:4}-${pkgver:4:2}-${pkgver:6:2}-${_owrtgit}"
source="https://sources.openwrt.org/libubox-${_owrtver}.tar.xz"
builddir="$srcdir/libubox-${_owrtver}"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CFLAGS="$CFLAGS -fPIC -DPIC" cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_LUA=OFF \
		-DBUILD_EXAMPLES=OFF \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

jshn() {
	amove usr/bin/jshn
	amove usr/share/libubox/jshn.sh
}

libblobmsg() {
	amove usr/lib/libblobmsg_json.so
	amove usr/lib/libjson_script.so
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
67cac344dc58bccd54937a8a32d8492be8b8d007b2419c3b90e6290d5ac995934c9de6f29f3a0e48382b9ef2af83ec2e4a2a97c346b4de2d42999b70eecfaf88  libubox-2023-05-23-75a3b870.tar.xz
"
